import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;
import java.util.Locale;

public class Test {
	public static void test(){
//		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
//		Date date=new Date("2016-12-26 08:26:00");
//		System.out.print(dateFormater.format(date));
		
		StringBuilder sb = new StringBuilder("2016-12-26 08:26:00");
		String str1 = "1970-01-06 11:45:55";
		String str2 = "2016-11-09 14:00:00";
		String str3 = "2016-11-09 13:00:00";
		String str4 = "2016-11-08 14:00:00";
		
		long currentTimeStamp = new Date().getTime();
		
//		System.out.println(formatTime2TimeStamp(str1));
//		
//		System.out.println(formatTime2TimeStamp(str2));
		
//		millis2MMSS(currentTimeStamp - formatTime2TimeStamp(str2));
//		millis2MMSS(currentTimeStamp - formatTime2TimeStamp(str3));
//		millis2MMSS(currentTimeStamp - formatTime2TimeStamp(str4));
		
//		System.out.println(formatTime2TimeStamp(str1));
//		System.out.println(formatTime2TimeStampChina(str1));
		
		System.out.println(getDate(str1));
		System.out.println(getDate(str2));
		System.out.println(getDate(str3));
		System.out.println(getDate(str4));
	}
	
	
	
	public static final SimpleDateFormat YYYY_MM_DD_HH_mm_ss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
    public static final SimpleDateFormat YYYY_MM_DD_HH_mm = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
    public static final SimpleDateFormat MM_DD_HH_mm = new SimpleDateFormat("MM月dd号 HH:mm", Locale.CHINA);
    public static final SimpleDateFormat YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
    public static final SimpleDateFormat HH_MM = new SimpleDateFormat("HH:mm", Locale.CHINA);
    public static final SimpleDateFormat MM_DD_CHINA = new SimpleDateFormat("MM月dd号", Locale.CHINA);
    
    
    /**
     * 将2016-11-11 10:20:55转成中文“11月11号 10:20”的时间格式
     *
     * @param time
     * @return
     */
    public static String getCN_Format(String time) {
        Date date = new Date();
        try {
            date = YYYY_MM_DD_HH_mm_ss.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return MM_DD_HH_mm.format(date);
    }
    

    /**
     * 将格式化的时间，转化为时间戳     
     * @param formatStr   2016-12-26 08:57:00  
     * @return 时间戳
     */
    public static long formatTime2TimeStamp(String formatStr){
    	 SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
    	    Date date;
			try {
				date = format.parse(formatStr);
				return date.getTime();
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
			return 0;
    }
    
    public static long formatTime2TimeStampChina(String formatStr){
   	 SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);  
   	    Date date;
			try {
				date = format.parse(formatStr);
				return date.getTime();
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
//   	    System.out.print("Format To times:"+ date.getTime());  
			return 0;
   }
    
    /**
     * 将中间相差的描述，转为为 ＊＊分＊＊秒 的形式,(也可能是 一分钟，)
     * 注意：方法采用的是 直接处以60的方式。并且分钟和秒数都是 
     * @param millis
     * @return
     */
    public static String millis2MMSS(long millis){
    	 SimpleDateFormat format =  new SimpleDateFormat("HH:mm:ss");  
    	    Long time=new Long(millis);  
    	    String d = format.format(time);  
    	    Date date;
			try {
				date = format.parse(d);
				System.out.println("date = " + date);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
			System.out.println("d = " + d);
			getMMSSByDivision(millis);
			System.out.println("-----------------");
			return "";
    }
    
    public static String getMMSSByDivision(long millis){
    	StringBuilder sb = new StringBuilder();
    	long second = millis / 1000;
    	long min = second / 60;
    	long hour = min / 60;
    	if (hour > 0){
    		sb.append("" + hour + "小时");
    	}
    	sb.append("" + (min%60) + "分钟");
    	sb.append("" + (second%60) + "秒");
    	
    	
    	System.out.println("sb = " + sb.toString());
    	
    	return sb.toString();
    }
    /**
     * 
     * @param timeStr 2016-11-08 14:00:00  
     * @return  2016-11-08  返回date的形式
     */
    private static  Date getDate(String timeStr){
    	Date date = new Date();
    	try {
			date = YYYY_MM_DD_HH_mm_ss.parse(timeStr);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return date;
    }
    
	
}
